from typing import List


class Solution:
    def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
        def count(s):
            c0 = 0
            c1 = 0
            for c in s:
                if c == '0':
                    c0 += 1
                else:
                    c1 += 1
            return c0, c1

        dp = [[[0 for _ in range(n + 1)] for _ in range(m + 1)] for _ in range(len(strs))]

        for k in range(len(strs)):
            c0, c1 = count(strs[k])
            for i in range(c0, m + 1):
                for j in range(c1, n + 1):
                    if k >= 1:
                        dp[k][i][j] = dp[k - 1][i - c0][j - c1] + 1
                    else:
                        dp[k][j][j] = 1
        return dp[-1][-1][-1]


if __name__ == '__main__':
    s = Solution()
    r = s.findMaxForm(strs=["10", "0001", "111001", "1", "0"], m=5, n=3)
    print(r)
